import java.util.Arrays;

//题目：
//给出一个有序的整数数组A和整数数组B 请将数组B合并到数组A中，百年城一个有序数组
//A数组的大小为m+n,A数组的大小为m,B数组的大小为n
public class Exercises {
    public void merge(int[] A,int[] B,int m,int n){
        int i = m - 1;
        int j = n - 1;
        int k = m + n - 1;
        while(i >= 0 && j >= 0){
            if(A[i] <= B[j]){
                A[k] = B[j];
                j--;
                k--;
            }else{
                A[k] = A[i];
                i--;
                k--;
            }
        }
        while(i >= 0){
            A[k] = A[i];
            i--;
            k--;
        }
        while(j >= 0){


            A[k] = B[j];
            j--;
            k--;
        }
    }

    public static void main(String[] args) {
        Exercises exercises = new Exercises();
        int[] A = new int[6];
        A[0] = 4;
        A[1] = 5;
        A[2] = 6;
        int[] B = {1,3,9};
        exercises.merge(A,B,3,3);
        System.out.println(Arrays.toString(A));
    }
}
